Automatic JSON Parsing
This feature automatically parses the JSON body of incoming HTTP requests and makes it available as a JavaScript object in `event.body`. This eliminates the need to manually parse the JSON string in each handler.
const middy = require('@middy/core');
const jsonBodyParser = require('@middy/http-json-body-parser');
const handler = middy((event, context) => {
// event.body is now a parsed JSON object
return {
statusCode: 200,
body: JSON.stringify({ message: 'Parsed body', data: event.body })
};
});
handler.use(jsonBodyParser());
module.exports = { handler };